package com.moif.ttakji.game;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class MyAdapter extends BaseAdapter implements MyItemView.OnItemImageClickListener{

	List<MyData> mData = new ArrayList<MyData>();
	Context mContext;
	
	OnAdapterItemImageClickListener mListener;
	public interface OnAdapterItemImageClickListener{
		public void onAdapterItemIamgeClick(MyData data);
	}
	
	public void setOnAdapterItemImageClickListener(OnAdapterItemImageClickListener listener){
		mListener = listener;
	}
	
	public MyAdapter(Context context){
		mContext = context;
	}
	
	public MyAdapter(Context context, List<MyData> items){
		mContext = context;
		mData.addAll(items);
	}
	
	public void add(MyData data){
		mData.add(data);
		notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		MyItemView view;
		if(convertView == null){
			view = new MyItemView(mContext);
			view.setOnItemImageClickListener(this);
		}else{
			view = (MyItemView)convertView;
		}//5�� �̻��϶� ������ x
		
		view.setData(mData.get(position));		
		return view;
	}

	@Override
	public void onItemImageClick(MyData data) {
		// TODO Auto-generated method stub
		if(mListener !=null){
			mListener.onAdapterItemIamgeClick(data);
		}
	}

}
